﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using VioletDevelopmentLaboratory.Net.Web;

public partial class vboard_membership_register : VioletDevelopmentLaboratory.Net.Web.PageBase
{
	protected void Page_Init(object sender, EventArgs e)
	{
		Page.Header.Title = GetLocalResourceObject("Title").ToString();
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			QuestionDropDownList_DataBind();

			birthdayForm();
		}
	}
	private void QuestionDropDownList_DataBind()
	{
		QuestionDropDownList.DataSource = VUtility.GetVWebGlobalResource("Membership_PasswordQuestions").Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
		QuestionDropDownList.DataBind();
	}

	protected void CreateUserButton_Click(object sender, EventArgs e)
	{
		if (Page.IsValid)
		{
			MembershipCreateStatus membershipCreateStatus;

			MembershipUser newUser = Membership.CreateUser(
				UserNameTextBox.Text,
				PasswordTextBox.Text,
				EmailTextBox.Text,
				QuestionDropDownList.SelectedValue,
				AnswerTextBox.Text,
				true,
				out membershipCreateStatus);

			String errorMessage = "";

			switch (membershipCreateStatus)
			{
				case MembershipCreateStatus.Success :
					newUser.Comment = CommentTextBox.Text;

					Membership.UpdateUser(newUser);

					/*ProfileCommon newProfile = Profile.GetProfile(newUser.UserName);

					if (!String.IsNullOrEmpty(YearDropDownList.SelectedValue) &&
						!String.IsNullOrEmpty(MonthDropDownList.SelectedValue) &&
						!String.IsNullOrEmpty(DayDropDownList.SelectedValue))
					{
						newProfile.SetPropertyValue("VWeb.Birthday_Year", Int32.Parse(YearDropDownList.SelectedValue));
						newProfile.SetPropertyValue("VWeb.Birthday_Month", Int32.Parse(MonthDropDownList.SelectedValue));
						newProfile.SetPropertyValue("VWeb.Birthday_Day", Int32.Parse(DayDropDownList.SelectedValue));
					}

					newProfile.SetPropertyValue("VWeb.Homepages", HomepagesTextBox.Text);
					newProfile.SetPropertyValue("VWeb.Interests", InterestsTextBox.Text);

					newProfile.Save();*/

					FormsAuthentication.SetAuthCookie(UserNameTextBox.Text, false);

					VUtility.GoToMessagePage(Page, VUtility.GetVWebGlobalResource("Membership_Do_Register_Success"), ResolveClientUrl("~/"), true, 3);
					break;
				case MembershipCreateStatus.DuplicateEmail:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_DuplicateEmail");
					break;
				case MembershipCreateStatus.DuplicateProviderUserKey:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_DuplicateProviderUserKey");
					break;
				case MembershipCreateStatus.DuplicateUserName:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_DuplicateUserName");
					break;
				case MembershipCreateStatus.InvalidAnswer:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_InvalidAnswer");
					break;
				case MembershipCreateStatus.InvalidEmail:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_InvalidEmail");
					break;
				case MembershipCreateStatus.InvalidPassword:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_InvalidPassword");
					break;
				case MembershipCreateStatus.InvalidProviderUserKey:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_InvalidProviderUserKey");
					break;
				case MembershipCreateStatus.InvalidQuestion:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_InvalidQuestion");
					break;
				case MembershipCreateStatus.InvalidUserName:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_UserName");
					break;
				case MembershipCreateStatus.ProviderError:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_ProviderError");
					break;
				case MembershipCreateStatus.UserRejected:
					errorMessage = VUtility.GetVWebGlobalResource("Membership_Do_Register_UserRejected");
					break;
			}

			VUtility.ShowMessagePanel(Page, errorMessage, true);
		}
	}








	private void birthdayForm()
	{
		/*YearDropDownList.Items.Add("");
		for (int i = DateTime.Now.Year - 7; i >= DateTime.Now.Year - 100; i--)
		{
			YearDropDownList.Items.Add(i.ToString());
		}

		MonthDropDownList.Items.Add("");
		for (int i = 1; i < 13; i++)
		{
			MonthDropDownList.Items.Add(i.ToString());
		}
		DayDropDownList.Items.Add("");
		for (int i = 1; i < 32; i++)
		{
			DayDropDownList.Items.Add(i.ToString());
		}*/
	}
	private void DayDropDownList_Bind()
	{
		/*if (!string.IsNullOrEmpty(YearDropDownList.SelectedValue) && !string.IsNullOrEmpty(MonthDropDownList.SelectedValue))
		{
			int days = DateTime.DaysInMonth(int.Parse(YearDropDownList.SelectedValue), int.Parse(MonthDropDownList.SelectedValue));

			DayDropDownList.Items.Clear();
			DayDropDownList.Items.Add("");

			for (int i = 1; i <= days; i++)
			{
				DayDropDownList.Items.Add(i.ToString());
			}
		}*/
	}
	protected void YearDropDownList_SelectedIndexChanged(object sender, EventArgs e)
	{
		//DayDropDownList_Bind();
	}
	protected void MonthDropDownList_SelectedIndexChanged(object sender, EventArgs e)
	{
		//DayDropDownList_Bind();
	}
}
